package com.qingcloud.adminbackend.controller;

import com.qingcloud.adminbackend.base.AjaxResult;
import com.qingcloud.adminbackend.entity.upgrade.UpgradeSpecialHisDTO;
import com.qingcloud.adminbackend.entity.upgrade.UpgradeSpecialRequest;
import com.qingcloud.adminbackend.service.impl.ITdUpgradeSpecialHisServiceImpl;
import com.qingcloud.adminbackend.utils.CookieUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(value = "升级站点信息", description = "升级站点信息")
@RestController
@RequestMapping("/upgradeSpecialHis")
public class TdUpgradeSpecialHisController {

    @Resource
    private ITdUpgradeSpecialHisServiceImpl upgradeSpecialHisService;

    /**
     * 分页查询
     *
     * @param upgradeSpecialRequest
     * @return
     */
    @ApiOperation(value = "分页查询历史升级站点信息", notes = "分页查询历史升级站点信息", response = UpgradeSpecialHisDTO.class)
    @PostMapping(value = "/getUpgradeSpecialHis")
    public AjaxResult getUpgradeSpecialHis(@RequestBody UpgradeSpecialRequest upgradeSpecialRequest) {
        return upgradeSpecialHisService.getUpgradeSpecialHis(upgradeSpecialRequest);
    }

    /***
     * 添加
     * @param upgradeSpecialHis
     * @param request
     * @return
     */
    @ApiOperation(value = "新增历史升级站点信息", notes = "新增历史升级站点信息")
    @PostMapping(value = "/addUpgradeSpecial")
    public AjaxResult addUpgradeSpecial(@RequestBody UpgradeSpecialHisDTO upgradeSpecialHis, HttpServletRequest request) {
        String userName = CookieUtil.getUserName(request);
        upgradeSpecialHis.setOperator(userName);
        return upgradeSpecialHisService.addUpgradeSpecialHis(upgradeSpecialHis);
    }


    /**
     * 获取指定历史升级站点信息
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "获取指定历史升级站点信息", notes = "获取指定id的历史升级站点信息", response = UpgradeSpecialHisDTO.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "升级站点ID", required = true, dataType = "string", paramType = "path", defaultValue = "1"),
    })
    @GetMapping(value = "/getUpgradeSpecialHisById/{id}")
    public AjaxResult getUpgradeSpecialHisById(@PathVariable("id") String id) {
        return upgradeSpecialHisService.getUpgradeSpecialHisById(id);
    }

    /**
     * 修改升级站点信息
     *
     * @param upgradeSpecialHis
     * @return
     */
    @ApiOperation(value = "修改升级站点信息", notes = "修改升级站点信息")
    @PostMapping(value = "/updateUpgradeSpecialHis")
    public AjaxResult updateUpgradeSpecialHis(@RequestBody UpgradeSpecialHisDTO upgradeSpecialHis, HttpServletRequest request) {
        String userName = CookieUtil.getUserName(request);
        upgradeSpecialHis.setOperator(userName);
        return upgradeSpecialHisService.updateUpgradeSpecialHis(upgradeSpecialHis);
    }

    /**
     * 删除升级站点信息
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "删除升级站点信息", notes = "删除升级站点信息")
    @PostMapping(value = "/deleteUpgradeSpecialHis")
    public AjaxResult deleteUpgradeSpecialHis(@RequestParam("ids[]") String[] ids) {
        return upgradeSpecialHisService.deleteUpgradeSpecialHis(ids);
    }

}
